{extend name="common:base" /}

{block name="page_title"}{$controllerName}授权{/block}

{block name="style"}
<style>
</style>
{/block}

{block name="content"}
<div class="box">
    <div class="box-header with-border"></div>
    <form class="form-horizontal ajaxForm3" name="form0" method="post" action="{:url('')}" onsubmit="onSubmit();">
        <input type="hidden" name="id" value="{$model['id']}">
        <input type="hidden" name="rules" id="h_rules" valign="">
        <div class="box-body">
            <label class="col-sm-2 control-label">组名</label>
            <div class="col-xs-10">
                {$model['title']}
            </div>
        </div>
        <div class="box-body" id="app">
            <label class="col-sm-2 control-label">权限</label>
            <div class="col-sm-10 rule_node">
                <ul id="treeDemo" class="ztree"></ul>
            </div>
        </div>
        <!-- /.box-body -->
        <div class="box-footer">
            <div class="row">
                <div class="col-xs-2"></div>
                <div class="col-xs-10">
                    <button type="submit" class="btn btn-info ladda-button" data-style="expand-left" data-plugin="ladda">
                        <span class="ladda-label"><i class="icon wb-arrow-expand margin-right-10" aria-hidden="true"></i>提交</span>
                    </button>
                    <a href="javascript:history.go(-1);" class="btn btn-default">返回</a>
                </div>
            </div>
        </div>
        <!-- /.box-footer -->
    </form>
</div>
{/block}

{block name="script"}
<script src="https://cdn.staticfile.org/zTree.v3/3.5.33/js/jquery.ztree.core.min.js"></script>
<script src="https://cdn.staticfile.org/zTree.v3/3.5.33/js/jquery.ztree.excheck.min.js"></script>
<script>
    var setting = {
        view: {
            selectedMulti: false
        },
        check: {
            enable: true
            ,chkboxType: { "Y": "", "N": "" }
        },
        data: {
            simpleData: {
                enable: true
                ,rootPId:0
                ,idKey: "id",
                pIdKey: "pId"
            }
        }
    };

    var zNodes = {$arTreeJson|raw};
    var treeObj;
    $(function(){
        treeObj = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
        treeObj.expandAll(true);
    });
    function onSubmit() {
        var nodes = treeObj.getCheckedNodes(true);
        var rules = [];
        $.each(nodes, function (n, value) {
            rules.push(value.id)
        });
        $('#h_rules').val(rules.join(','))
    }
</script>
{/block}